import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/controller/evaluation.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/grids/evaluationRecordDataGrid.dart';

class EvaluationRecordsForStudent extends StatefulWidget {
  static const String routeName = '/student/evaluation/records';

  @override
  State<EvaluationRecordsForStudent> createState() =>
      _EvaluationRecordsForStudentState();
}

class _EvaluationRecordsForStudentState
    extends State<EvaluationRecordsForStudent> {
  final box = Hive.box('appconfig');
  final EvaluationController controller = Get.find();

  @override
  void initState() {
    bool isStudent = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Student;
    Future.delayed(Duration(milliseconds: 100), () {
      if (isStudent) {
        controller.fetchEvaluationRecords('0', '0', '', '');
      }
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build student evaluation records');

    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Column(
        children: [
          //Expanded(child: EvaluationRecordDataGrids(_questionRecords, false)),
          Expanded(
            child: controller.obx(
              (data) => Container(
                child: EvaluationRecordDataGrids(
                    controller.evaluationRecordItems, false),
              ),
              onEmpty: EvaluationRecordDataGrids(
                  controller.evaluationRecordItems, false),
              onLoading: Container(),
            ),
          ),
        ],
      ),
    );
  }
}
